﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Newtonsoft.Json;
using System.Web.SessionState;

namespace AjaxLibrary
{
    class priceStructure : IHttpHandler, IRequiresSessionState
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string param = context.Request.QueryString["Param"];
            switch (param)
            {
                case "adminSubmitPriceModulus": adminSubmitPriceModulus(context.Request,context.Response); break;
                default:
                    context.Response.Output.Write("Unknow request URL!");
                    break;
            }
        }

        private void adminSubmitPriceModulus(HttpRequest request, HttpResponse response)
        {
            try
            {
                int companyId = 0;
                int productId = 0;
                decimal productAutoAdd = 0m;
                decimal autoPercent = 0m;

                int.TryParse(request.QueryString["productId"], out productId);
                int.TryParse(request.QueryString["companyId"], out companyId);
                decimal.TryParse(request.QueryString["productAutoAdd"], out productAutoAdd);
                decimal.TryParse(request.QueryString["autoPercent"], out autoPercent);

                if (companyId != 0 && productId != 0)
                {
                    logic.priceStructure.update(companyId, productId, productAutoAdd, autoPercent,logic.sysAdmin.AdminID);
                    response.Output.Write("1");
                }
            }
            catch
            {
                response.Output.Write("2");
            }
        }

        #endregion
    }
}
